package kr.couponplay.android.support;

import android.annotation.SuppressLint;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@SuppressLint("SimpleDateFormat") 
public class DateUtils {
	public static int ONE_YEAR = 60 * 60 * 24 * 365;  
	
	/**
	 * @param textDate yyyyMMddHHmmss
	 */
	public static Date toDate(String textDate, String pattern) {
		SimpleDateFormat format = new SimpleDateFormat(pattern);
		Date date;
		try {
			date = format.parse(textDate);
		} catch (ParseException e) {
			return new Date();
		}
		return date;
	}
	
	public static String toString(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH시 mm분");
		return format.format(date);
	}

	public static int getTodayCount(Date startDate) {
		Date nowDate = new Date();
		int days =(int)((nowDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)); 
		return days + 1;
	}
	
	public static Date getYesterday() {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, -1);
		return cal.getTime();
	}
}
